<?php

declare(strict_types=1);

namespace app\common\service\sys;

use app\common\traits\ServiceTrait;
use app\common\service\sys\FilesService;
use app\common\dao\sys\FilesGroupDao;

/**
 * 上传文件分组
 * @author:kaige
 * @date:2022-06-12
 * @copyright ©2022 泉州市盛筑信息科技有限公司 版权所有
 */
class FilesGroupService
{
  protected $dao = null;

  public function __construct()
  {
    $this->dao = new FilesGroupDao();
  }
  use ServiceTrait;

  /**
   * 添加分组
   */
  public function addGroup($data)
  {
    if (!$data['name']) {
      return _err(1002);
    }
    $res = $this->dao->getInfoByName($data['name']);
    if ($res) {
      return _err(3011);
    }
    if ($this->dao->add($data)) {
      return _ok(1023);
    }
    return _err(1024);
  }


  /**
   * 删除分组
   */
  public function deleteGroup($group_id)
  {
    if (!$group_id) {
      return _err(1002);
    }
    if ($group_id < 8) {
      return _err('此分组不能删除');
    }
    $filesS = new FilesService();
    if ($this->dao->delete($group_id)) {
      //移入未分组
      $filesS->update($group_id, ['group_id' => 7]);
      return _ok(1025);
    }
    return _err(1026);
  }
}
